package view;

import java.awt.Button;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.List;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import device.DeviceHelper;

public class TesteDelete extends Panel {

    private static final long serialVersionUID = 1L;

    private Label label2 = null;

    private List list = null;

    private Panel panel = null;

    private Panel panel1 = null;

    private Button button = null;

    private Button button1 = null;

    private Label label4 = null;

    private final DeviceRevome deviceRevome;

    /**
     * This is the default constructor
     * @param deviceRevome 
     */
    public TesteDelete(DeviceRevome deviceRevome) {
        super();
        this.deviceRevome = deviceRevome;
        setSize(500, 500);
        setBackground(Color.WHITE);
        setLocation(135, 85);
        initialize();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        GridBagConstraints gridBagConstraints111 = new GridBagConstraints();
        gridBagConstraints111.gridx = 3;
        gridBagConstraints111.gridy = 2;
        label4 = new Label();
        //label4.setText("Label");
        GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
        gridBagConstraints9.gridx = 2;
        gridBagConstraints9.gridy = 4;
        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
        gridBagConstraints5.fill = GridBagConstraints.BOTH;
        gridBagConstraints5.gridy = 2;
        gridBagConstraints5.weightx = 1.0;
        gridBagConstraints5.weighty = 1.0;
        gridBagConstraints5.gridheight = 1;
        gridBagConstraints5.anchor = GridBagConstraints.SOUTH;
        gridBagConstraints5.gridx = 2;
        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
        gridBagConstraints4.gridx = 2;
        gridBagConstraints4.gridy = 0;
        label2 = new Label();
        label2.setText("Excluir Equipamento");
        label2.setFont(new Font("Arial", Font.BOLD, 15));
        this.setSize(300, 200);
        this.setLayout(new GridBagLayout());
        //this.setBackground(new DVBColor(0, 255, 0, 100));
        this.add(label2, gridBagConstraints4);
        this.add(getList(), gridBagConstraints5);
        this.add(getPanel1(), gridBagConstraints9);
        //this.add(label4, gridBagConstraints111);
    }

    /**
     * This method initializes list	
     * 	
     * @return java.awt.List	
     */
    private List getList() {
        if (list == null) {
            list = new List();
            loadList();
        }
        return list;
    }

    /**
     * This method initializes panel	
     * 	
     * @return java.awt.Panel	
     */
    private Panel getPanel() {
        if (panel == null) {
            panel = new Panel();
            panel.setLayout(new GridBagLayout());
        }
        return panel;
    }

    /**
     * This method initializes panel1	
     * 	
     * @return java.awt.Panel	
     */
    private Panel getPanel1() {
        if (panel1 == null) {
            GridLayout gridLayout = new GridLayout();
            gridLayout.setRows(1);
            gridLayout.setColumns(2);
            panel1 = new Panel();
            panel1.setLayout(gridLayout);
            panel1.add(getButton(), null);
            panel1.add(getButton1(), null);
        }
        return panel1;
    }

    /**
     * This method initializes button	
     * 	
     * @return java.awt.Button	
     */
    private Button getButton() {
        if (button == null) {
            button = new Button();
            button.setLabel("Excluir");
            button.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    DeviceHelper.getInstance().removeDevice(list.getSelectedItem());
                    loadList();
                    deviceRevome.requestFocus();
                }
            });
        }
        return button;
    }

    private void loadList() {
        list.removeAll();
        java.util.List<String> devicesName = DeviceHelper.getInstance().getDevicesNames();
        for (String name : devicesName) {
            list.add(name);
        }
    }

    /**
     * This method initializes button1	
     * 	
     * @return java.awt.Button	
     */
    private Button getButton1() {
        if (button1 == null) {
            button1 = new Button();
            button1.setLabel("Voltar");
        }
        return button1;
    }

}
